package gui;
import javax.swing.AbstractButton;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JSeparator;
import Entity.*;
import controllers.ManagerUIP;
import controllers.OBLSettings;
import controllers.WelcomeUIP;
import messagesPacks.*;

import java.awt.*;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.util.Date;
import java.util.Enumeration;
import messagesPacks.*;
import javax.swing.JList;
import javax.swing.border.BevelBorder;
import javax.swing.border.MatteBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
/**
 * @author Ariel Brucker
 * The UI CLASS FOR THE Borrow Report(GUI)
 */
public class ManagerBorrowReportUI extends JPanel
{
	private static final long serialVersionUID = 1L;
	public JButton btnLogout;
	public JButton btnExit;
	ManagerUIP muip=null; 
	public SimpleTable SubTable;
	private JButton btnBack;
	private JLabel lblOblManager;
	ManagerMainUI managerMainUI=null;
	private JTextField regularBooksAVG;
	private JTextField regularBooksMedian;
	private JLabel lblRegularBooksMedian;
	private JLabel lblRegularBooksAVG;
	private final JSeparator separator = new JSeparator();
	private JTextField wantedBooksAVG;
	private JTextField wantedBooksMedian;
	private JLabel lblWantedBooksAVG;
	private JLabel lblWantedBooksMedian;
	private JLabel lblDistribution;
	public BorrowStatisticsMSG borrowStatisticsMSG;
	public ManagerBorrowReportUI(ManagerMainUI managerMainUI) 
	{
		super();
		this.managerMainUI=managerMainUI;
		System.out.println("ManagerSuspendSub created.");
		this.muip=new ManagerUIP();
		initialize();
	}
	private void initialize()
	{
		borrowStatisticsMSG=muip.CreateBorrowReport();
		this.setSize(OBLSettings.pane2Size[0],OBLSettings.pane2Size[1]);
		setLayout(null);
    	separator.setBounds(0, 57, 855, 30);
		add(separator);
		lblOblManager = new JLabel("OBL Manager-Borrow Report");
		lblOblManager.setFont(new Font("Tahoma", Font.BOLD, 20));
		lblOblManager.setBounds(173, 0, 368, 58);
		add(lblOblManager);
		btnExit = new JButton("Exit");
		btnExit.setFont(new Font("Tahoma", Font.BOLD, 15));
		btnExit.setBounds(707, 11, 83, 41);
		add(btnExit);
		btnBack = new JButton("Back");
		btnBack.setFont(new Font("Tahoma", Font.BOLD, 15));
		btnBack.setBounds(10, 11, 83, 41);
		add(btnBack);
		btnLogout = new JButton("Logout");
		btnLogout.setFont(new Font("Tahoma", Font.BOLD, 15));
		btnLogout.setBounds(614, 11, 83, 41);
		add(btnLogout);
	    
	    regularBooksAVG = new JTextField();
		regularBooksAVG.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		regularBooksAVG.setBounds(296, 71, 48, 24);
		regularBooksAVG.setFont(new Font("Tahoma", Font.PLAIN, 15));
		add(regularBooksAVG);
		regularBooksAVG.setColumns(10);
		regularBooksAVG.setEnabled(false);
		regularBooksAVG.setText(Double.toString(borrowStatisticsMSG.not_wanted_avg));
		
		regularBooksMedian = new JTextField();
		regularBooksMedian.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		regularBooksMedian.setBounds(298, 124, 48, 24);
		regularBooksMedian.setFont(new Font("Tahoma", Font.PLAIN, 15));
		add(regularBooksMedian);
		regularBooksMedian.setColumns(10);
		regularBooksMedian.setEnabled(false);
		System.out.println("borrowStatisticsMSG.not_wanted_avg="+borrowStatisticsMSG.not_wanted_avg);
		regularBooksMedian.setText(Double.toString(borrowStatisticsMSG.not_wanted_median));
		
		lblRegularBooksAVG = new JLabel("The Regular Books Average days of Borrow=");
		lblRegularBooksAVG.setBounds(20, 70, 281, 24);
		lblRegularBooksAVG.setFont(new Font("Tahoma", Font.PLAIN, 14));
		add(lblRegularBooksAVG);
		
		lblRegularBooksMedian = new JLabel("The Regular Books Median days of Borrow=");
		lblRegularBooksMedian.setBounds(20, 123, 281, 24);
		lblRegularBooksMedian.setFont(new Font("Tahoma", Font.PLAIN, 14));
		add(lblRegularBooksMedian);
		
		lblWantedBooksAVG = new JLabel("The Wanted Books Average days of Borrow=");
		lblWantedBooksAVG.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblWantedBooksAVG.setBounds(20, 182, 281, 24);
		add(lblWantedBooksAVG);
		
		wantedBooksAVG = new JTextField();
		wantedBooksAVG.setFont(new Font("Tahoma", Font.PLAIN, 15));
		wantedBooksAVG.setColumns(10);
		wantedBooksAVG.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		wantedBooksAVG.setBounds(298, 186, 48, 24);
		add(wantedBooksAVG);
		wantedBooksAVG.setEnabled(false);
		wantedBooksAVG.setText(Double.toString(borrowStatisticsMSG.wanted_avg));
		
		lblWantedBooksMedian = new JLabel("The Wanted Books Median days of Borrow=");
		lblWantedBooksMedian.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblWantedBooksMedian.setBounds(20, 244, 281, 24);
		add(lblWantedBooksMedian);
		
		wantedBooksMedian = new JTextField();
		wantedBooksMedian.setFont(new Font("Tahoma", Font.PLAIN, 15));
		wantedBooksMedian.setColumns(10);
		wantedBooksMedian.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		wantedBooksMedian.setBounds(296, 248, 48, 24);
		add(wantedBooksMedian);
		wantedBooksMedian.setEnabled(false);
		wantedBooksMedian.setText(Double.toString(borrowStatisticsMSG.wanted_median));
		
		lblDistribution = new JLabel("Distribution of the Borrows");
		lblDistribution.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblDistribution.setBounds(297, 294, 180, 24);
		add(lblDistribution);
		
		Object ColNames[] = { "Days of Borrow", "Number of Books", "Wanted"};
		SubTable = new SimpleTable(null, ColNames, 10, 328, 780, 198);
	    add(SubTable.tblScrollPane,BorderLayout.CENTER);
	    
	    //BorrowStatistics
	     for (BorrowStatistics var : borrowStatisticsMSG.getborrowStatisticsArr())
        {
			SubTable.model.addRow(new Object[] {var.getDuration(),var.getNumOfBooks(),var.getWanted()});
        }
		
	     btnBack.addActionListener(new ActionListener() 
	     {
	     	public void actionPerformed(ActionEvent e) 
	     	{
	     		 WelcomeUI.wui.switchPanel("OBL Manager",managerMainUI ,OBLSettings.pane2Size[0], OBLSettings.pane2Size[1]);
	     	}
	     });
	}
	public void paintComponent(Graphics g) 
	{
		g.drawImage((OBLSettings.IMG_DEFAULT_BACKGROUND).getImage(), 0, 0, OBLSettings.pane2Size[0], OBLSettings.pane2Size[1],null);
		
	}
}
